/**
 * Copyright (C), 2019-2022, 宇信融汇
 * FileName: DelayedPublisherTest
 * Author:   666
 * Date:     2022/4/22 18:42
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 666           修改时间           版本号              描述
 */
package com.mashibing.rabbitmq_boot;

import com.mashibing.rabbitmq_boot.config.DelayedConfig;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @Classname DelayedPublisherTest
 * @Description TODO
 * @Date 2022/4/22 18:42
 * @Created by 666
 */
@SpringBootTest
public class DelayedPublisherTest {
    @Autowired
    public RabbitTemplate rabbitTemplate;

    @Test
    public void publish(){
        rabbitTemplate.convertAndSend(DelayedConfig.DELAYED_EXCHANGE, "delayed.abc", "xxxx", new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setDelay(15000);
                return message;
            }
        });
    }
}
